package com.fulin.sycnLife;

public class TestNum {
	private static ThreadLocal<Integer> seqNum = new ThreadLocal<Integer>(){
		public Integer initialValue(){
			return 0;
		}
	};
	
	public int getNextNum(){
		seqNum.set(seqNum.get() + 1);
		return seqNum.get();
	}
	
	private static class TestClient extends Thread{
		private TestNum sn;
		
		public TestClient(TestNum sn){
			this.sn = sn;
		}
		
		public void run(){
			for(int i =0;i < 3;i ++){
				System.out.println("thread[" + Thread.currentThread().getName() + "] --> sn[" + sn.getNextNum() + ']');
			}
		}
	}
	
	public static void main(String[] args) {
		TestNum sn = new TestNum();
		for(int i =0 ;i<3;i++){
			new TestClient(sn).start();
		}
	}
}
